package fiscal.entities.tables;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;

import exceptions.PersistenceExceptionMessage;
import fiscal.dao.PersistenceEstados;
import generic.interfaces.GenericPersistence;
import generic.interfaces.IDEntity;
import generic.interfaces.PersistInFile;

@SuppressWarnings("rawtypes")
@Entity
public class Estado implements IDEntity<String>, GenericPersistence<PersistenceEstados, String, Estado>, PersistInFile, Comparable<Estado> {

	public static PersistenceEstados persist = new PersistenceEstados();
	
	@Id
	@Column(length=2)
	private String uf;
	@Column(length=30)
	private String nome;
	@Column(precision=3)
	private Double aliquota;
	
	
	public String getId() {
		return this.uf;
	}
	
	public void setId(String uf) {
		this.uf = uf;
	}
	public String getNome() {
		return nome;
	}
	public void setNome(String nome) {
		this.nome = nome;
	}
	
	
	public int compareTo(Estado o) {
		return getNome().toUpperCase().compareTo(o.getNome().toUpperCase());
	}

	
	public Object getInstanceFromArray(String[] str) {
		// TODO Auto-generated method stub
		return null;
	}

	@SuppressWarnings("unchecked")
	
	public Collection order(ArrayList entities) {
		Collections.sort(entities);
		return entities;
	}

	
	public int removeAll() throws PersistenceExceptionMessage {
		return DAOInstance().removeAll();
	}

	
	public ArrayList getArrayAsString() throws PersistenceExceptionMessage {
		return null;
	}

	
	public PersistenceEstados DAOInstance() throws PersistenceExceptionMessage {
		if (persist == null) {
			persist = new PersistenceEstados();
		}
		return persist;
	}

	
	public void persist() throws PersistenceExceptionMessage {
		DAOInstance().persist(this);
	}

	
	public void remove() throws PersistenceExceptionMessage {
		DAOInstance().remove(this);
	}

	
	public Estado merge() throws PersistenceExceptionMessage {
		return DAOInstance().merge(this);
	}

	
	public ArrayList<Estado> findAll() throws PersistenceExceptionMessage {
		return (ArrayList<Estado>) DAOInstance().findAll();
	}
	
	public String toString() {
		return getId();
	}
	
	public boolean equals(Object obj) {
		if (obj instanceof Estado) {
			Estado estado = (Estado) obj;
			return getId().equals(estado.getId());
		}
		return false;
	}
	
	public Estado find(String id) throws PersistenceExceptionMessage {
		return DAOInstance().find(id);
	}
	public Double getAliquota() {
		return aliquota;
	}
	public void setAliquota(Double aliquota) {
		this.aliquota = aliquota;
	}
}
